let categoryList = [{id: 1, name: '手机数码'}, {id: 2, name: '电脑办公'}, {id: 3, name: '潮流服饰'}, {id: 4, name: '图书影音'}]

let listList = ``;
categoryList.forEach(e => {
    listList += `<li class="nav-item">
                <a class="nav-link active" href="category.html?cid=${e.id}">${e.name}</a>
             </li>`;
});

//从sessionStorage中获得用户信息
let data=sessionStorage.getItem("user");
let loginBlock='';
let cartBlock='';
if (data == null || data == undefined){
        loginBlock=`<a class="nav-link" href="login.html">登录</a>`
        cartBlock=` <a class="nav-link" href="regist.html">注册</a>`
}else {
        let  user=JSON.parse(data);
        loginBlock=`<a class="nav-link" href="my.html">${user.username}</a>`
        cartBlock =`<a class="nav-link" href="cart.html">购物车</a>`
}

let nav = `<!--页面导航-->
<nav class="navbar navbar-expand-lg navbar-light " style="background-color: rgb(91, 156, 156);">
  <div class="container-fluid">
    <a class="navbar-brand" href="index.html">简易购</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText"
      aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">
         ${listList}
        <li class="nav-item">
          <form class="d-flex" role="search">
            <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
            <button class="btn btn-outline-success" type="submit">Search</button>
          </form>
        </li>
      </ul>

        ${loginBlock}
      <span class="navbar-text">
        ${cartBlock}
      </span>
    </div>
  </div>
</nav>
<!-- /页面导航 -->`;
document.write(nav);